package com.erci.controller.user;

import com.erci.entity.Episode;
import com.erci.entity.VO.AnimeDetailVO;
import com.erci.result.PageResult;
import com.erci.result.Result;
import com.erci.service.AnimeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@CrossOrigin(origins = "http://localhost:5172")
@RestController("userAnimeController")
@RequestMapping("/user/anime")
@Slf4j
public class AnimeController {
    @Autowired
    private AnimeService animeService;

    @GetMapping("/list")
    public Result<PageResult> queryListUser(Integer page, Integer pageSize, String name,
                                            Integer categoryId, String year ) {
        PageResult pageResult = animeService.queryListUser(page,pageSize, name,categoryId,year);
        return Result.success(pageResult);
    }

    @GetMapping("/detail/{id}")
    public Result<AnimeDetailVO> queryDetail(@PathVariable Integer id){
        AnimeDetailVO animeDetailVO = animeService.queryDetail(id);
        return Result.success(animeDetailVO);
    }

    @GetMapping("/{id}/episodes")
    public Result<List<Episode>> queryEpisodes(@PathVariable Integer id){
        List<Episode> episodes = animeService.queryEpisodes(id);
        return Result.success(episodes);
    }
}
